home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / BOOZ_MAC / BOOZ_2 / PORTABLE.C < prev    next >
Text File  |  1992-07-19  |  3KB  |  120 lines

  1. /* 
  2. This file is public domain.
  3.                                    -- Rahul Dhesi 1991/07/07
  4. */
  5.  
  6. typedef char BYTE;      /* MUST be an 8-bit value */
  7.  
  8. #include "booz.h"
  9. #include "zoo.h"
  10. #include <stdio.h>
  11.  
  12. long to_long ();
  13. int to_int ();
  14. int b_to_zooh();
  15. int b_to_dir();
  16.  
  17. /**********************
  18. to_long() converts four consecutive bytes, in order of increasing
  19. significance, to a long integer.  It is used to make Zoo independent of the
  20. byte order of the system.  
  21. */
  22. long to_long(data)
  23. BYTE data[];
  24. {
  25.    long retval;
  26.    retval = ((unsigned) data[2] & 0xff) | 
  27.       (((unsigned) data[3] & 0xff) << 8);
  28.    retval <<= 16;
  29.    retval |= (((unsigned) data[0] & 0xff) | 
  30.       (((unsigned) data[1] & 0xff) << 8));
  31.    return (retval);
  32. }
  33.  
  34. /**********************
  35. to_int() converts two consecutive bytes, in order of increasing
  36. significance, to an integer, in a machine-independent manner
  37. */
  38. int to_int(data)
  39. BYTE data[];
  40. {
  41.    return (int) (((unsigned) data[0] & 0xff) | 
  42.       ((unsigned) (data[1] & 0xff) << 8));
  43. }
  44.  
  45. /**********************
  46. Function rd_zooh() reads a Zoo archive header in a machine-dependent manner,
  47. from an open file.
  48. */
  49. int rd_zooh (header, zoofile)
  50. struct zoo_header *header;
  51. FILE *zoofile;
  52. {
  53.    int status;
  54.    BYTE bytes[SIZ_ZOOH];
  55.    status = fread((char *) bytes, 1, SIZ_ZOOH, zoofile);
  56.    b_to_zooh (header, bytes);
  57.    return status;
  58. }
  59.  
  60. /**********************
  61. Function rd_dir() reads a directory entry in a machine-independent manner
  62. from an open file.
  63. */
  64. int rd_dir(direntry, zoofile)
  65. struct direntry *direntry;
  66. FILE *zoofile;
  67. {
  68.    int status;
  69.    BYTE bytes[SIZ_DIR];
  70.    status = fread((char *) bytes, 1, SIZ_DIR, zoofile);
  71.    b_to_dir (direntry, bytes);
  72.    return (status);
  73. }
  74.  
  75. /***********************
  76. b_to_zooh() converts an array of BYTE to a zoo_header structure.
  77. */
  78. int b_to_zooh (zoo_header, bytes)
  79. struct zoo_header *zoo_header;
  80. BYTE bytes[];
  81. {
  82.    int i;
  83.    for (i = 0; i < SIZ_TEXT; i++)
  84.       zoo_header->text[i] = bytes[TEXT_I + i];
  85.    zoo_header->lo_tag = to_int(&bytes[ZTAG_I]);
  86.    zoo_header->hi_tag = to_int(&bytes[ZTAG_I+2]);
  87.    /* zoo_header->zoo_tag = to_long(&bytes[ZTAG_I]); */
  88.    zoo_header->zoo_start = to_long(&bytes[ZST_I]);
  89.    zoo_header->zoo_minus = to_long(&bytes[ZSTM_I]);
  90.    zoo_header->major_ver = bytes[MAJV_I];
  91.    zoo_header->minor_ver = bytes[MINV_I];
  92. }
  93.  
  94. /* b_to_dir() converts bytes to directory entry structure */
  95. int b_to_dir(direntry, bytes)
  96. struct direntry *direntry;
  97. BYTE bytes[];
  98. {
  99.    int i;
  100.    direntry->lo_tag = to_int(&bytes[DTAG_I]);
  101.    direntry->hi_tag = to_int(&bytes[DTAG_I+2]);
  102.    /* direntry->zoo_tag = to_long(&bytes[DTAG_I]); */
  103.    direntry->type = bytes[DTYP_I];
  104.    direntry->packing_method = bytes[PKM_I];
  105.    direntry->next = to_long(&bytes[NXT_I]);
  106.    direntry->offset = to_long(&bytes[OFS_I]);
  107.    direntry->date = to_int(&bytes[DAT_I]);
  108.    direntry->time = to_int(&bytes[TIM_I]);
  109.    direntry->file_crc = to_int(&bytes[CRC_I]);
  110.    direntry->org_size = to_long(&bytes[ORGS_I]);
  111.    direntry->size_now = to_long(&bytes[SIZNOW_I]);
  112.    direntry->major_ver = bytes[DMAJ_I];
  113.    direntry->minor_ver = bytes[DMIN_I];
  114.    direntry->deleted = bytes[DEL_I];
  115.    direntry->comment = to_long(&bytes[CMT_I]);
  116.    direntry->cmt_size = to_int(&bytes[CMTSIZ_I]);
  117.    for (i = 0; i < FNM_SIZ; i++)
  118.       direntry->fname[i] = bytes[FNAME_I + i];
  119. }
  120.